package com.mozz.finally_work.dao;

import com.mozz.finally_work.pojo.Tag;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface TagDao {

    /*添加标签*/
    @Insert("INSERT INTO tag(id,name) values(#{id},#{tagName})")
    Integer addTag(@Param("id") String id, @Param("tagName") String tagName);

    /*获取所有的标签*/
    @Select("SELECT tag.*,count(*) as count FROM tag join blog_tag on tag.id=blog_tag.tag_id group by tag.id")
    @Results(value = {
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "count", property = "count"),
    })
    List<Tag> queryAllTag();

    /*获取所有的标签*/
    @Select("SELECT tag.* FROM tag ")
    @Results(value = {
            @Result(id = true, column = "id", property = "id"),
    })
    List<Tag> queryAllTagName();

    /*根据文章id查询标签*/
    @Select("SELECT tag.* FROM tag join blog_tag on tag.id=blog_tag.tag_id join blog on blog.id=blog_tag.blog_id where blog.id=#{blogId}")
    List<Tag> queryTagByBlogId(String blogId);
}
